<?php

/**
 * Created by PhpStorm.
 * User: feng
 * Date: 2016/12/19
 * Time: 下午1:35
 */
class Permission
{
    public function __construct()
    {
        // Assign the CodeIgniter super-object
        $this->CI =& get_instance();
    }

//    public function
    public static function check()
    {
        sessionOpen();
        if (!isset($_SESSION['user_id']) || empty($_SESSION['user_id']) || !isset($_SESSION['user_type']) || empty($_SESSION['user_type'])) {
            header('location:' . site_url('/admin/login'));
            exit('illegal');
        }
    }

    public static function administratorCheck()
    {
        sessionOpen();
        if (!isset($_SESSION['user_id']) || empty($_SESSION['user_id']) || !isset($_SESSION['user_type']) || empty($_SESSION['user_type'])) {
            header('location:' . site_url('/admin/login'));
            exit('illegal');
        }
        if ($_SESSION['user_type'] != 3) {
            exit('illegal');
        }
    }

    /**
     * 是否有权限领取任务
     */
    public static function getTask()
    {
        sessionOpen();
        if (!isset($_SESSION['user_id']) || !isset($_SESSION['user_type']) || $_SESSION['user_type'] != 1) {
            //判断是否存在未完成的任务
            return false;
        } else {
            return true;
        }
    }

    /**
     * 译员验证
     */
    public static function yy($code = 0)
    {
        sessionOpen();
        if (isset($_SESSION['user_id']) && !empty($_SESSION['user_id']) && isset($_SESSION['user_type']) && $_SESSION['user_type'] == 1) {
            return true;
        } else {
            if ($code == 0) {
                header('location:' . site_url('/admin/login'));
                exit;
            } elseif ($code == 1) {
                exit('Illegal operation !');
            }
            return false;
        }
    }

    /**
     * 任务专员验证
     */
    public static function zy($code = 0)
    {
        sessionOpen();
        if (isset($_SESSION['user_id']) && !empty($_SESSION['user_id']) && isset($_SESSION['user_type']) && $_SESSION['user_type'] == 2) {
            return true;
        } else {
            if ($code == 0) {
                header('location:' . site_url('/admin/login'));
                exit;
            } elseif ($code == 1) {
                exit('Illegal operation !');
            }
            return false;
        }
    }

    /**
     * 管理员验证
     */
    public static function gl($code = 0)
    {
        sessionOpen();
        if (isset($_SESSION['user_id']) && !empty($_SESSION['user_id']) && isset($_SESSION['user_type']) && $_SESSION['user_type'] == 3) {
            return true;
        } else {
            if ($code == 0) {
                header('location:' . site_url('/admin/login'));
                exit;
            } elseif ($code == 1) {
                exit('Illegal operation !');
            }
            return false;
        }
    }

    /**
     * 运营工作人员验证
     */
    public static function gz($code = 0)
    {
        sessionOpen();
        if (isset($_SESSION['user_id']) && !empty($_SESSION['user_id']) && isset($_SESSION['user_type']) && $_SESSION['user_type'] == 4) {
            return true;
        } else {
            if ($code == 0) {
                header('location:' . site_url('/admin/login'));
                exit;
            } elseif ($code == 1) {
                exit('Illegal operation !');
            }
            return false;
        }
    }
}